home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / prio / _list_pq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.3 KB  |  70 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _list_pq.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <LEDA/impl/list_pq.h>
  16.  
  17. list_pq::list_pq(const list_pq&) { /* copy constructor */}
  18.  
  19. list_pq& list_pq::operator=(const list_pq&) { /* assignment */ return *this; }
  20.  
  21.  
  22. list_pq_item list_pq::insert(GenPtr k,GenPtr i) 
  23. { copy_key(k);
  24.   copy_inf(i); 
  25.   list_pq_item p = new list_pq_elem(k,i,nil,head);
  26.   if (head) head->pred = p;
  27.   head = p;
  28.   count++;
  29.   return p; 
  30. }
  31.  
  32. list_pq_item list_pq::find_min() const  
  33. { list_pq_item p = head;
  34.   list_pq_item m = head;
  35.   if (int_type())
  36.      while (p)
  37.      { if (long(p->key) < long(m->key)) m = p;
  38.        p = p->succ;
  39.       }
  40.   else
  41.      while (p)
  42.      { if (cmp(p->key,m->key) < 0) m = p;
  43.        p = p->succ;
  44.       }
  45.   return m;
  46.  }
  47.  
  48.  
  49. void list_pq::del_item(list_pq_item it)     
  50. { list_pq_item p = it->pred;
  51.   list_pq_item s = it->succ;
  52.   if (p) p->succ = s;
  53.   else   head = s;
  54.   if (s) s->pred = p;
  55.   count--;
  56.  }
  57.  
  58.  
  59. void list_pq::clear()   
  60. { while (head)
  61.   { list_pq_item p = head->succ;
  62.     clear_key(head->key);
  63.     clear_inf(head->inf);
  64.     delete head;
  65.     head = p;
  66.    }
  67.   count = 0;
  68.  }
  69.